package com.zhbit.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.zhbit.Service.CommentService;
import com.zhbit.Service.ContentmangerService;
import com.zhbit.table.Share;

public class ContentdetailsAction extends ActionSupport{
	private int id;
	private ContentmangerService cs;
	private List sharelist;
	private CommentService ts;
	private List commentlist;
public CommentService getTs() {
		return ts;
	}
	public void setTs(CommentService ts) {
		this.ts = ts;
	}
	public List getCommentlist() {
		return commentlist;
	}
	public void setCommentlist(List commentlist) {
		this.commentlist = commentlist;
	}
/**
	 * @return the sharelist
	 */
	public List<Share> getSharelist() {
		return sharelist;
	}
	/**
	 * @param sharelist the sharelist to set
	 */
	public void setSharelist(List<Share> sharelist) {
		this.sharelist = sharelist;
	}
/**
	 * @return the cs
	 */
	public ContentmangerService getCs() {
		return cs;
	}
	/**
	 * @param cs the cs to set
	 */
	public void setCs(ContentmangerService cs) {
		this.cs = cs;
	}
/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
   public String execute() throws Exception {
	   cs.addwatchcount(id);
	   List results=cs.findByid(id);
		ArrayList lists=new ArrayList();
		for (int i = 0; i < results.size(); i++) {
		     Object []o=(Object [])results.get(i);
		     HashMap p=new HashMap();	      
		        p.put("content",(String)o[0]);
		        p.put("title",(String)o[1]);
		        p.put("imagpath",(String)o[2]);
		        p.put("watchcount",(Integer)o[3]);
		        p.put("sharetime",(Date)o[4]);
		        p.put("likecount",(Integer)o[5]);
		        p.put("username", (String)o[6]);
		        p.put("id",(Integer)o[7]);
		        lists.add(p);
		    }
		setSharelist(lists);
		List result=ts.findAll(id);
		ArrayList list=new ArrayList();
		for (int i = 0; i < result.size(); i++) {
		     Object []o=(Object [])result.get(i);
		     HashMap p=new HashMap();	      
		        p.put("content",(String)o[0]);
		        p.put("commenttime",(Date)o[1]);
		        p.put("headimg",(String)o[2]);
		        p.put("username",(String)o[3]);

		        list.add(p);
		    }
			
			setCommentlist(list);
		return SUCCESS;
	}
}
